using UnityEngine;
using System.Collections;

/// \class  gkAbyssalGiantSubmarineMovementController
/// \brief  The submarine movement controller
[AddComponentMenu("GK/AbyssalGiant/Submarine/gkAbyssalGiantSubmarineMovementController")]
public class gkAbyssalGiantSubmarineMovementController : MonoBehaviour
{
    /// The maximum speed
    public const float MaxSpeed = 15;

    /// The input
    private gkAbyssalGiantSubmarineInput m_rSubmarineInput;

    /// The physic component
    private gkPhysicComponent m_rPhysicComponent;

    /// \brief  Called just after the game begin to play
    void Start()
    {
        // Grab the input
        m_rSubmarineInput = GetComponent<gkAbyssalGiantSubmarineInput>();

        // Grab the physic component
        m_rPhysicComponent = GetComponent<gkPhysicComponent>();

	    // Set the max velocity
        m_rPhysicComponent.SetMaximumLinearVelocity(MaxSpeed);
    }

    /// \brief  Event called each frame
    void Update()
    {
	    Vector3 f3CurrentVelocity;

	    // Compute the percentage of tilt
        f3CurrentVelocity = m_rSubmarineInput.GetTiltPercent() * MaxSpeed;

	    // Apply forces
        m_rPhysicComponent.SetLinearVelocity(f3CurrentVelocity);
    }
}
